package org.smart4j.framework.proxy;

import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;
import java.util.List;

/**
 *
 * 代理管理器
 *
 * @author: Mr.Zhou
 * @create: 2018-10-25 15:57
 **/
public class ProxyManager {

    /**
     * 创建代理对象
     * @param <T>
     * @return
     */
    public static <T> T createProxy(final Class<T> targetClass, final List<Proxy> porxyList){
        return (T) Enhancer.create(targetClass, new MethodInterceptor() {
            @Override
            public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
                return new ProxyChain(targetClass,o,method,methodProxy,objects,porxyList);
            }
        });
    }
}
